#案例：使用BS4库来解析html标签！

import requests
from bs4 import BeautifulSoup #导入bs4库

#发请求：GET https://shop.aircheng.com/
r=requests.get(url="https://shop.aircheng.com/")

#获取响应内容：String
response_body=r.text

#把字符串类型的响应实体封装成soup对象
soup = BeautifulSoup(response_body,'lxml');


#函数原型：List sup.select(String CSS选择器);
#函数功能：使用CSS选择器语法来获取满足该CSS选择器语法的N个标签！

#定位到你需要操作的标签
eles_a=soup.select("body > div.home_content > section.hotsale > div > div.index_card_container > a:nth-child(2)")
ele_baobei=eles_a[0] #<a class="home_pul_box_shadow" href="/site/products/id/21">xxx</a>

#获取该标签的所有属性名和属性值
attrs=ele_baobei.attrs
for attr_name,attr_value in attrs.items():
    print(attr_name,attr_value)


#----------------------------------
eles_section=soup.select("body > div.home_content > section.home_activity.recommend")
ele_section=eles_section[0]

for k,v in ele_section.attrs.items():
    print(k,v)

#获取class属性的值
attr_class=ele_section["class"]
for x in attr_class:
    print(x)